import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;
public class TCSerial {
	public String recordNo = null;
	public String sys_Batch = null;
	public String errMsg = null;
	public String rfRecordNo = null;
	public String rfBatch = null;
	public String getRecordNo(){
		String Msg = null;
		try {
			FileReader fr = new FileReader("/home/tcserver/etc/serial.cfg");
			BufferedReader br= new BufferedReader(fr);
			recordNo = br.readLine().trim();
			while(recordNo.length() < 6){
				recordNo = "0"+recordNo;
			}
			fr.close();
			br.close();
			Date date = new Date();
			SimpleDateFormat sdfdate = new SimpleDateFormat("yyyyMMdd");
			String nowDate = sdfdate.format(date);
			Msg = nowDate+recordNo;
		}catch(IOException e){
			e.printStackTrace();
		}
		return Msg;
	}
	public String getBatch(){
		String Msg = null;
		try{
		FileReader fr = new FileReader("/home/tcserver/etc/sysbatch.cfg");
		BufferedReader br= new BufferedReader(fr);
		sys_Batch = br.readLine().trim();
		fr.close();
		br.close();
		Date date = new Date();
		SimpleDateFormat sdfdate = new SimpleDateFormat("yyyyMMdd");
		String nowDate = sdfdate.format(date);
		Msg = nowDate+sys_Batch;
		}catch(IOException e){
			e.printStackTrace();
		}
		return Msg;
	}
	public void setRecordNo(){
		try{
			FileWriter fw = new  FileWriter("/home/tcserver/etc/serial.cfg");
			BufferedWriter bw = new BufferedWriter(fw);
			int intRecordNo = Integer.parseInt(recordNo);
			intRecordNo++;
			if(intRecordNo >= 999999){
				intRecordNo = 1;
			}
			bw.write(Integer.toString(intRecordNo));
			bw.close();
		}catch(IOException e){
			e.printStackTrace();
		}
	}
	public void setBatch(){
		try{
			FileWriter fw = new  FileWriter("/home/tcserver/etc/sysbatch.cfg");
			BufferedWriter bw = new BufferedWriter(fw);
			int intSys_Batch = Integer.parseInt(sys_Batch);
			intSys_Batch++;
			if(intSys_Batch >= 9999){
				intSys_Batch = 1;
			}
			bw.write(Integer.toString(intSys_Batch));
			bw.close();
		}catch(IOException e){
			e.printStackTrace();
		}
	}

}
